package kr.saeildamil.androidstudy_second.multimedia;

import java.io.IOException;

import kr.saeildamil.androidstudy_second.R;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;

public class PlayVideo extends Activity {
	private SurfaceView mPreView;
	private SurfaceHolder mHolder;
	MediaPlayer mPlayer;
	Button mPlayBtn;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch33_playvideo);
		
		mPreView = (SurfaceView)findViewById(R.id.surface);
		mHolder = mPreView.getHolder();
		//mHolder.addCallback(this);
		
		mPlayBtn = (Button)findViewById(R.id.play);
	}
	@Override
	protected void onPause() {
		super.onPause();
		if(mPlayer!=null){
			mPlayer.release();
			mPlayer = null;
		}
	}
	public void mOnClick(View v){
		switch(v.getId()){
		case R.id.play:
			if(!mPlayer.isPlaying()){
				mPlayer.start();
				mPlayBtn.setText("Pause");
			}else{
				mPlayer.pause();
				mPlayBtn.setText("Play");
			}
			break;
		case R.id.stop:
			mPlayer.stop();
			try {
				mPlayer.prepare();
			} catch (IllegalStateException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			break;
			
		}
	}
	public void surfaceCreated(SurfaceHolder holder){
		if(mPlayer == null){
			mPlayer = new MediaPlayer();
		}else{
			mPlayer.reset();
		}
		String sd= Environment.getExternalStorageDirectory().getAbsolutePath();
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
}
